<template />

<script>
export default {
  name: 'TransitProduct',
  components: {},
  props: {},
  data() {
    return {
      query: {},
      previousStatus: 0
    };
  },
  computed: {},
  watch: {},
  onLoad(query) {
    this.query = query;
    // 处理通过小程序码进入的场景逻辑
    if (query.scene) {
      const scene = this.$tools.param2Object(query.scene);
      this.query.productId = scene.id;
    } else {
      this.query.productId = query.productId || query.id;
    }
  },
  onShow() {
    const pages = getCurrentPages();
    const params = {
      ...this.query
    };
    switch (this.previousStatus) {
      case 1:
        Object.assign(params, {
          source: 1027
        });
        break;
      case 2:
        if (pages.length <= 1) {
          // 没有得再返回了，就直接回首页
          return uni.switchTab({
            url: '/pages/index/index'
          });
        } else {
          return uni.navigateBack({
            delta: 1
          });
        }
    }

    const query = this.$tools.object2param(params);
    console.log(query);
    wx.navigateTo({
      url: `/packages/goods-detail/index?${query}`
    });
  },
  onHide() {
    // 离开中转页后，状态改为2，避免商品页逻辑出错，导致退不出去
    this.previousStatus = 2;
  },
  methods: {}
};
</script>

<style>

</style>
